/*
 * Copyright (c) 2024 endless-sky
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef EL_PROTOCOL_MODEL_HANDLER_H
#define EL_PROTOCOL_MODEL_HANDLER_H

#include "command_handler_base.h"
#include <string>
#include <unordered_map>
#include <functional>
#include <nlohmann/json.hpp>

namespace El {
namespace Protocol {

/**
 * @brief 模型管理处理器
 * 处理模型上传、下载、删除等相关命令
 */
class ModelHandler : public CommandHandlerBase {
public:
    /**
     * @brief 注册方法处理器
     * @param handlers 方法处理器映射表
     */
    void RegisterMethodHandlers(
        std::unordered_map<std::string, std::function<nlohmann::json(const std::string&, const nlohmann::json&)>>& handlers);

private:
    // 处理模型上传请求
    nlohmann::json HandleModelUpload(const std::string& id, const nlohmann::json& params);
    
    // 处理模型列表请求
    nlohmann::json HandleModelList(const std::string& id, const nlohmann::json& params);
    
    // 处理模型下载请求
    nlohmann::json HandleModelDownload(const std::string& id, const nlohmann::json& params);
    
    // 处理模型删除请求
    nlohmann::json HandleModelDelete(const std::string& id, const nlohmann::json& params);

    // 模型上传状态结构
    struct UploadStatus {
        std::string fileName;
        std::string modelDescription;
        size_t totalSize = 0;
        int totalChunks = 0;
        int uploadedChunks = 0;
        std::string tempFilePath;
    };

    // 当前上传状态
    UploadStatus uploadStatus_;
};

} // namespace Protocol
} // namespace El

#endif // EL_PROTOCOL_MODEL_HANDLER_H